package com.baizhi.service.impl;

import com.baizhi.dao.UserDao;
import com.baizhi.User;
import com.baizhi.service.UserService;
import com.baizhi.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements UserService {

    @Override
    public boolean login(String name, String pwd) {
        SqlSession sqlSession = MyBatisUtils.openSession();
        try {
            UserDao mapper = sqlSession.getMapper(UserDao.class);
            User user = mapper.findUser(name, pwd);
            if (user==null){
                return  false;
            }else{
                if (name.equals(user.getUserName())&&pwd.equals(user.getPassword())){
                    return  true;
                }
            }
        } catch (Exception e) {
            throw  new RuntimeException(e);
        } finally {
            sqlSession.close();
        }
        return false;
    }
}
